package com.gxa.controller;

import com.gxa.common.R;
import com.gxa.pojo.Goods;
import com.gxa.pojo.Orders;
import com.gxa.service.OrdersService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;


@Controller
@RequestMapping("/orders")
@Api(value = "订单管理Test",tags = "订单管理接口API")

public class OrdersController {
    private  R r=new R();
    @Autowired(required = false)
    private OrdersService ordersService;
    /**
     * 查询订单信息
     */
    @RequestMapping(value = "/queryOrderList",method = RequestMethod.GET)
    @ApiOperation(value = "查询订单列表接口",notes = "订单列表信息",httpMethod = "get", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",paramType = "query",dataType = "int",required = true),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryOrderList(@RequestParam(value = "currentPage") Integer currentPage,@RequestParam(value = "pageSize") Integer pageSize){
//        Orders orders=new Orders();
//        orders.setOrder_id("DD1546725621");
//        orders.setOrder_date(new Date(2021-12-03));
//        orders.setOrder_amount(new BigDecimal(2000));
//        orders.setOrder_status(1);
//        orders.setShipping_status(2);
//        orders.setOrder_remark("订单列表信息");
//        r.setData(orders);
//        r.setCode(200);
//        r.setMsg("操作成功");
        R r=ordersService.queryOrdersList(currentPage,pageSize);
        return r;
    }

    /**
     * 搜索订单信息的方法
     * @return
     */

    @RequestMapping(value = "/search",method = RequestMethod.GET)
    @ApiOperation(value = "搜索订单接口",notes = "搜索订单信息",httpMethod = "get", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "conn",value = "接收参数(客户名称，手机号码，订单编号)",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",paramType = "query",dataType = "int",required = true),
    })

    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R search(String conn,Integer currentPage,Integer pageSize){
//        r.setData("顾客名称");
//        r.setData(1519684885);
//        r.setData("DD1234564852323");
//        r.setCode(200);
//        r.setMsg("操作成功");
        R r=ordersService.search(conn,currentPage,pageSize);
        return r;
    }


    /**
     * 修改订单信息的方法
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "修改订单接口",notes = "修改订单信息",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R update(@RequestBody @ApiParam Map map){
//        r.setCode(200);
//        r.setMsg("操作成功");
        System.out.println(map);
        R r=ordersService.updatreByOrders_Id(map);
        return r;
    }
    /**
     * 删除订单信息的方法
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ApiOperation(value = "删除订单接口",notes = "删除订单信息",httpMethod = "post", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "order_id",value = "订单编号",paramType = "query",dataType = "String",required = true),
    })

    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R delete(String order_id,int status){

//        r.setCode(200);
//        r.setMsg("操作成功");
        R r=ordersService.deleteById(order_id,status);
        return r;
    }

    /**
     * 根据客户名称来查询客户订单信息
     */

    @RequestMapping(value = "/queryByCustomer_id",method = RequestMethod.GET)
    @ApiOperation(value = "查看客户订单信息接口",notes = "通过点击客户名称来查询客户订单信息",httpMethod = "get", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customer_id",value = "客户id",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "currentPage",value = "当前页数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",required = true,dataType = "int",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryByCustomer_name(Integer customer_id,Integer currentPage,Integer pageSize){
//        r.setData("DD1256131651");
//        r.setData(new Date(2021-12-03));
//        r.setData(2000);

        R r=ordersService.queryByName(customer_id,currentPage,pageSize);
        return r;
    }

    /**
     * 根据订单编号查询订单信息
     */

    @RequestMapping(value = "/queryByOrder_id",method = RequestMethod.GET)
    @ApiOperation(value = "查看订单信息接口",notes = "通过点击订单编号来查询订单信息",httpMethod = "get", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "order_id",value = "订单编号",paramType = "query",dataType = "String",required = true),
    })

    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryByOrder_id(String order_id){
//        r.setData("DD1256131651");
//        r.setData(new Date(2021-12-03));
//        r.setData(2000);
        R r=ordersService.queryByOrder_id(order_id);
        return r;
    }

    /**
     * 查询今日新增订单
     */
    @RequestMapping(value = "/queryTodayOrders",method = RequestMethod.GET)
    @ApiOperation(value = "今日新增接口",notes = "查询今日新增订单",httpMethod = "get", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",paramType = "query",dataType = "int",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryTodayOrders(Integer currentPage,Integer pageSize){
        R r=ordersService.queryByTodayOrder_date(currentPage,pageSize);
        return r;
    }

    /**
     * 查询本周新增订单
     */
    @RequestMapping(value = "/queryWeekOrders",method = RequestMethod.GET)
    @ApiOperation(value = "本周新增接口",notes = "查询本周新增订单",httpMethod = "get", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",paramType = "query",dataType = "int",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryWeekOrders(Integer currentPage,Integer pageSize){
        R r=ordersService.queryWeekByOrder_date(currentPage,pageSize);
        return r;
    }

    /**
     * 查询本月新增订单
     */
    @RequestMapping(value = "/queryMonthOrders",method = RequestMethod.GET)
    @ApiOperation(value = "本月新增接口",notes = "查询本月新增订单",httpMethod = "get", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",paramType = "query",dataType = "int",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryMonthOrders(Integer currentPage,Integer pageSize){
        R r=ordersService.queryMonthByOrder_date(currentPage,pageSize);
        return r;
    }

    /**
     * 新增订单接口
     */
    @RequestMapping(value = "/addOrders",method = RequestMethod.GET)
    @ApiOperation(value = "新增订单接口",notes = "查询新增订单",httpMethod = "get", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",paramType = "query",dataType = "int",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R addOrders(Integer currentPage,Integer pageSize){
        R r=ordersService.queryOrders(currentPage,pageSize);
        return r;
    }

    /**
     * 新增订单搜索的方法
     * @return
     */

    @RequestMapping(value = "/searchAddOrders",method = RequestMethod.GET)
    @ApiOperation(value = "新增订单搜索接口",notes = "新增订单搜索信息",httpMethod = "get", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "argument",value = "接收参数(客户名称，联系人，手机号码)",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",paramType = "query",dataType = "int",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R searchAddOrders(String argument,Integer currentPage,Integer pageSize){
        R r=ordersService.searchAddOrders(argument,currentPage,pageSize);
        return r;
    }

    /**
     * 新增订单里点击客户名称进行新增订单
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value = "根据客户名称新增订单接口",notes = "根据客户名称新增订单信息",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R add(@RequestBody @ApiParam Map map){
        System.out.println("进入成功");
        R r=ordersService.add(map);
        return r;
    }

    /**
     * 订单统计方法（按员工）
     */

    @RequestMapping(value = "/countOrdersByEmployee",method = RequestMethod.POST)
    @ApiOperation(value = "通过员工统计订单数据",notes = "通过员工统计订单数据",httpMethod = "POST", response = R.class)
    @ResponseBody
    public R countDocumentaryByEmployee(@RequestParam (name = "start_time",required = true)String start_time,@RequestParam (name = "stop_time",required = true)String stop_time){
        R r=ordersService.countOrdersByEmployee(start_time,stop_time);
        return r;
    }

    /**
     *订单统计方法（按部门）
     */
    @RequestMapping(value = "/countOrdersByDept",method = RequestMethod.POST)
    @ApiOperation(value = "通过部门统计订单数据",notes = "通过部门统计订单数据",httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start_time",value = "开始时间",dataType = "String",paramType = "query",required = true),
            @ApiImplicitParam(name = "stop_time",value = "结束时间",dataType = "String",paramType = "query",required = true),
    })
    @ResponseBody
    public R countOrdersByDept(@RequestParam (name = "start_time",required = true)String start_time,@RequestParam (name = "stop_time",required = true)String stop_time){
        R r=ordersService.countOrdersByDept(start_time,stop_time);

        return r;
    }


    /**
     * 修改订单已收款金额
     * @param received
     * @return
     */
    @RequestMapping(value = "/updateReceived", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改收款金额",notes = "收款金额",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=300,message="数据类型错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateReceived(Integer received, @RequestParam String order_id){
        return ordersService.updateReceived(received,order_id);
    }
    /**
     * 修改订单状态
     * @param status
     * @param order_id
     * @return
     */
    @RequestMapping(value = "/updatStatus", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改订单状态",notes = "状态选项",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=300,message="数据类型错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public  R updateStatus(@RequestParam(value = "status")Integer status,@RequestParam(value = "order_id") String order_id){
        return ordersService.updateStatus(status,order_id);
    }

    /**
     * 修改订单发货状态
     * @param shippingStatus
     * @return
     */
    @RequestMapping(value = "/updatShippingStatus", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改发货状态",notes = "状态选项",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=300,message="数据类型错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateShippingStatus(@RequestParam("shippingStatus") Integer shippingStatus,@RequestParam("order_id") String order_id){
        return ordersService.updateShippingStatus(shippingStatus,order_id);
    }


    /**
     * 查询订单商品
     * @param order_id
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryOrderGoods", method = RequestMethod.GET)
    @ApiOperation(value = "查询订单商品",notes = "订单编号",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=300,message="数据类型错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R queryOrderGoods(String order_id,Integer currentPage,Integer pageSize){
        return ordersService.queryOrderGoods(order_id,currentPage,pageSize);
    }


    //    @RequestMapping(value = "/queryGoods", method = RequestMethod.GET)
//    @ResponseBody
//    @ApiOperation(value = "查询订单商品",httpMethod = "get", response = R.class, produces = "application/json;charset=utf-8")
//    @ApiResponses({
//            @ApiResponse(code=200,message="请求成功"),
//            @ApiResponse(code=300,message="数据类型错误"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
//    public R queryGoods(){
//        R r = new R();
//        r.setCode(200);
//        r.setMsg("测试成功");
//        return r;
//    }
    /**
     * 添加订单商品
     * @return
     */
    @RequestMapping(value = "/addGoodOrder", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加订单商品",notes = "查询获得的订单商品参数",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=300,message="数据类型错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R addGoodOrder(@RequestParam("order_id") String order_id,@RequestParam("goods_id") Integer goods_id){
        return ordersService.addGoodOrder(order_id,goods_id);
    }

    /**
     * 删除订单商品
     * @param order_id
     * @param order_goods_id
     * @param order_goods_status
     * @return
     */
    @RequestMapping(value = "/deleteOrderGoods", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除订单商品", notes = "该订单商品信息",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=300,message="数据类型错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteOrderGoods(@RequestParam("order_id") String order_id,@RequestParam("order_goods_id") Integer order_goods_id,Integer order_goods_status){
        return ordersService.deleteOrderGoods(order_id,order_goods_id,order_goods_status);
    }

    /**
     * 新增查询商品
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryGoods",method = RequestMethod.GET)
    @ApiOperation(value = "商品查询接口",notes = "当前页码数和每页显示条数",httpMethod = "get",response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",paramType = "query",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",paramType = "query",dataType = "int",required = true)
    })
    @ResponseBody
    public R queryGoods(@RequestParam(name = "currentPage")Integer currentPage,@RequestParam(name ="pageSize" )Integer pageSize){
        return ordersService.queryGoods(currentPage,pageSize);

    }

    /**
     * 修改订单商品的信息
     *
     * @return
     */
    @RequestMapping(value = "/updateOrderGoods", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改订单商品信息", notes = "修改字段参数",httpMethod = "post", response = R.class)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "order_id",value = "订单编号",paramType = "query",dataType = "String",required = true),
//            @ApiImplicitParam(name = "order_goods_id",value = "订单商品id",paramType = "query",dataType = "int",required = true),
//            @ApiImplicitParam(name = "order_goods_count",value = "商品数量",paramType = "query",dataType = "int",required = true),
//            @ApiImplicitParam(name = "discount",value = "折扣",paramType = "query",dataType = "int"),
//            @ApiImplicitParam(name = "order_goods_remark",value = "备注",paramType = "query",dataType = "String"),
//    }

//    )
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=300,message="数据类型错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateOrderGoods(@RequestBody Map map){
        return ordersService.updateOrderGoods(map);
    }


    /**
     * 查询订单提成
     * @return
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    @ApiOperation(value = "订单提成",httpMethod = "get",response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ResponseBody
    public R findAll(){
        return ordersService.findAll();
    }


}
